<template>
	<view class="page-wallet">
		<view class="form">
			<view class="item">
				<view class="label">
					钱包名称
				</view>
				<view class="input-box">
					<input type="text" placeholder-style="color:#666" placeholder="请输入钱包名称" v-model="walletName" />
				</view>
				<view class="tip">名称可由汉字、字母或数字组成，限制4-12个字符</view>
			</view>
			<view class="item">
				<view class="label">
					安全密码
				</view>
				<view class="input-box">
					<input type="text" password="" placeholder-style="color:#666" placeholder="请输入安全密码"
						v-model="password" />
				</view>
				<view class="tip">密码必须为8-16位大小写字母和数字的组合</view>
			</view>
			<view class="item">
				<view class="label">
					确认安全密码
				</view>
				<view class="input-box">
					<input type="text" password="" placeholder-style="color:#666" placeholder="请输入安全密码"
						v-model="rePassword" />
				</view>
			</view>
			<view class="item">
				<view class="label">
					邀请码
				</view>
				<view class="input-box">
					<input type="text" placeholder-style="color:#666" placeholder="邀请码" v-model="inviteCode" />
				</view>
			</view>
		</view>
		<view class="button-box-padding">
			<button class="btn-primary" @click="createWallet">确认</button>
		</view>
	</view>
</template>

<script>
	import api from "@/utils/api/wallet/index.js"
	import util from '@/common/util.js'

	export default {
		data() {
			return {
				walletName: "",
				password: "",
				rePassword: "",
				inviteCode: "",
			}
		},
		methods: {
			async createWallet() {
				let checkWalletName = util.checkItem("wallet_name", this.walletName)
				let checkPassword = util.checkItem("password", this.password)
				let checkInviteCode = util.checkItem("invite_code", this.inviteCode);
				if (!checkWalletName.status) {
					util.showError(checkWalletName.message);
					return
				}
				if (!checkPassword.status) {
					util.showError(checkPassword.message);
					return
				}
				if (this.password != this.rePassword) {
					util.showError("两次密码输入不一致");
					return
				}
				if (!checkInviteCode.status) {
					util.showError(checkInviteCode.message);
					return
				}
				let post = {
					'wallet_name': this.walletName,
					'password': this.password,
					'invite_code': this.inviteCode
				}

				let result = await api.createWallet(post)
				if (result.status == 1) {
					uni.setStorageSync("user", result.data);
					uni.navigateTo({
						url: "save-recovery-phrase?wallet_data=" + JSON.stringify(result.data)
					})
				}


			}
		}
	}
</script>

<style lang="scss">

</style>
